package com.mljr.example.http;

import com.ctakit.sdk.exception.BusinessException;
import com.mljr.example.base.Config;
import com.mljr.example.base.Global;
import com.mljr.example.bean.AppVersion;
import com.mljr.example.bean.MyLocaction;
import com.mljr.example.bean.tab1.ChannelIcon;
import com.mljr.example.bean.tab1.HomeBanner;
import com.mljr.example.bean.tab1.Merchant;
import com.mljr.example.bean.tab1.Voucher;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class HttpServices extends BaseHttpServices {

    /**
     * 版本更新
     *
     * @return
     * @throws BusinessException
     */
    public static AppVersion upgrade() throws BusinessException {

        String url = Config.Server.getBaseUrl() + "/app/android/getVersionInfo";
        Map<String, String> params = new TreeMap<String, String>();
        return getResultDataByGet(url, params, AppVersion.class, false);

    }


//    ///////////////////////////////////////////////////新项目开始/////////////////////
//    //用户登录
//    public static LoginUser login(String userName, String password) throws BusinessException {
//        String url = Config.Server.getBaseUrl() + Signature.getMethod(AppUtils.getContext(), 1);
//        Map<String, String> params = new TreeMap<String, String>();
//        params.put("nickName", userName);
//        params.put("password", password);
//        params.put("pushToken", Global.getPushToken());
//        params.put("os", Global.os + "");
//        return getResultDataByPost(url, params, LoginUser.class, false);
//    }

    /**
     * 上传通讯录
     *
     * @return
     * @throws BusinessException
     */
    public static Boolean uploadPhone(String contacts) throws BusinessException {
        String url = Config.Server.getBaseUrl() + "/consumer/saveContacts";
        Map<String, String> params = new TreeMap<String, String>();
        params.put("contacts", contacts);
        return getResultDataByPost(url, params, Boolean.class, false);
    }

    /**
     * app banner
     *
     * @return
     * @throws BusinessException
     */
    public static List<HomeBanner> getHomeBannerList() throws BusinessException {
        String url = Config.Server.getBaseUrl() + "/home/queryBannerListForApp?deviceType=1";
        Map<String, String> params = new TreeMap<String, String>();
        return getResultListDataByGet(url, params, HomeBanner.class, false);
    }

    public static List<ChannelIcon> getHomeIconList() throws BusinessException {
        String url = Config.Server.getBaseUrl() + "/home/queryIconList?deviceType=2";
        Map<String, String> params = new TreeMap<String, String>();
        return getResultListDataByGet(url, params, ChannelIcon.class, false);
    }
    public static List<Voucher> getVoucherList() throws BusinessException {
        String url = Config.Server.getBaseUrl() + "/voucher/queryList?currPage=1&pageSize=20";
        Map<String, String> params = new TreeMap<String, String>();
        return getResultListDataByGet(url, params, Voucher.class, false);
    }
    public static List<Merchant> getMerchantList(int currPage, int pageSize) throws BusinessException {
        String url = Config.Server.getBaseUrl() + "/merchant/queryList";
        MyLocaction myLocaction = Global.getMapLocation();
        Map<String, String> params = new TreeMap<String, String>();
        params.put("currPage",currPage+"");
        params.put("pageSize",pageSize+"");
        if(myLocaction!=null&&myLocaction.getLatitude()>0){
            params.put("latitude",myLocaction.getLatitude()+"");
            params.put("longitude",myLocaction.getLongitude()+"");
        }


        return getResultListDataByGet(url, params, Merchant.class, false);
    }


}
